

cc.Class({
    extends: cc.Component,

    properties: {
     bg1:cc.Node,
     bg2:cc.Node,
     //计分
     scoreboard:cc.Label,

     //屏幕移动速度
     speed:10,
     
     //敌机预制件
     boss:[cc.Prefab],

    //陨石预制件
    Meteorite:[cc.Prefab],

   
    },

   

    
    onLoad () {
         //启动碰撞管理器
    var manager = cc.director.getCollisionManager();
    manager.enabled = true;
    
    //生成敌机
    this.schedule(this.battleplane,2);
    //生成陨石
    this.schedule(this.Meteorites,8);
  
    },

    begin_schedule:function(){
        //生成敌机
        this.schedule(this.battleplane,1);
        //生成陨石
        this.schedule(this.Meteorites,8);
    },

    //停止生成敌机，陨石
    stop_schedule:function(){

        this.unschedule(this.battleplane);
        this.unschedule(this.Meteorites);
    
    },

    battleplane:function(){
    var planenum = parseInt(Math.random()*this.boss.length);

     var battleplane = window.Global.getClassAndAdd(this.boss[planenum],"Boss",this.node); 
     battleplane.tClass.init(planenum);
    },

    Meteorites:function(){
        var planenum = parseInt(Math.random()*this.Meteorite.length);

         var Meteorite = window.Global.getClassAndAdd(this.Meteorite[planenum],"Meteorite",this.node); 
         Meteorite.tClass.init(planenum);
    },

    

    start () {

    },

     update (dt) {
    this.scoreboard.string =  "score:" + window.Global.score;


    //屏幕背景移动
     this.bg1.y -= this.speed;
     this.bg2.y -= this.speed;
     
    if(this.bg1.y <= -this.bg1.height){
        this.bg1.y = this.bg1.height;
    }

    if(this.bg2.y <= -this.bg2.height){
        this.bg2.y = this.bg2.height;
    }

     },
});
